using Project3D.my3D.Base;
using System;
using System.Collections.Generic;

namespace Project3D.my3D.Structure
{

    public class myVertex
    {
        //Extra variable. Useful in algorithms for storing extra information. Use however you like.
        public int v_id;

        //The 3D point position for this vertex.
        public myPoint3D point;

        //The 3D normal vector for this vertex.
        public myVector3D normal;

        //Link to any halfedge to which this vertex is the origin.
        public myHalfedge originof_halfedge;

        public int flag;

        public myVertex()
        {
            point = new myPoint3D();
        }

        public myVertex(myPoint3D _point)
        {
            point = _point;
        }

        public void setPoint(myPoint3D _point)
        {
            point.X = _point.X;
            point.Y = _point.Y;
            point.Z = _point.Z;
        }

        public myVertex Copy()
        {
            myVertex tmp = new myVertex();
            tmp.v_id = this.v_id;
            tmp.point = this.point.Copy();
            if (this.normal != null)
                tmp.normal = this.normal.Copy();

            return tmp;
        }

        public Matrix4 GetQuadric()
        {
            Matrix4 Q = new Matrix4();

            Q.matrix[0, 0] = 1;
            Q.matrix[1, 1] = 1;
            Q.matrix[2, 2] = 1;
            Q.matrix[3, 3] = 1;

            Q.matrix[0, 3] = -point.X;
            Q.matrix[1, 3] = -point.Y;
            Q.matrix[2, 3] = -point.Z;
            Q.matrix[3, 3] = point.X * point.X + point.Y * point.Y + point.Z * point.Z;

            Q.matrix[3, 0] = Q.matrix[0, 3];
            Q.matrix[3, 1] = Q.matrix[1, 3];
            Q.matrix[3, 2] = Q.matrix[2, 3];

            return Q;
        }
    }

}
